//
//  MyShipmentOperationCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/10/26.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "MyShipmentOperationCell.h"
#import "XLPhotoBrowser.h"

@interface MyShipmentOperationCell ()<XLPhotoBrowserDelegate>

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *title1Lab;
@property (nonatomic, strong) UILabel *name1Lab;
@property (nonatomic, strong) UILabel *title2Lab;
@property (nonatomic, strong) UIButton *look1Btn;
@property (nonatomic, strong) UILabel *title3Lab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UILabel *title4Lab;
@property (nonatomic, strong) UILabel *name2Lab;
@property (nonatomic, strong) UILabel *title5Lab;
@property (nonatomic, strong) UIButton *look2Btn;
@property (nonatomic, strong) UIImageView *statusImgView;

@end

@implementation MyShipmentOperationCell

+ (instancetype)MyShipmentOperationCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"MyShipmentOperationCell";
    MyShipmentOperationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MyShipmentOperationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.title1Lab = [UILabel new];
        self.title1Lab.textColor = HexColor(0x9C9DB3);
        self.title1Lab.font = [UIFont systemFontOfSize:14];
        self.title1Lab.text = @"签收操作人：";
        [self.bgView addSubview:self.title1Lab];
        
        self.name1Lab = [UILabel new];
        self.name1Lab.textColor = HexColor(0x2B2C44);
        self.name1Lab.font = [UIFont systemFontOfSize:14];
        self.name1Lab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.name1Lab];
        
        self.title2Lab = [UILabel new];
        self.title2Lab.textColor = HexColor(0x9C9DB3);
        self.title2Lab.font = [UIFont systemFontOfSize:14];
        self.title2Lab.text = @"签收附件：";
        [self.bgView addSubview:self.title2Lab];
        
        self.look1Btn = [UIButton new];
        [self.look1Btn setTitleColor:Color_ThemeColor forState:0];
        self.look1Btn.titleLabel.font = BoldFontOfSize(14);
        self.look1Btn.titleLabel.textAlignment = NSTextAlignmentRight;
        [self.look1Btn addTarget:self action:@selector(look1Click) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.look1Btn];
        
        self.title3Lab = [UILabel new];
        self.title3Lab.textColor = HexColor(0x9C9DB3);
        self.title3Lab.font = [UIFont systemFontOfSize:14];
        self.title3Lab.text = @"签收备注：";
        [self.bgView addSubview:self.title3Lab];
        
        self.contentLab = [UILabel new];
        self.contentLab.textColor = HexColor(0x2B2C44);
        self.contentLab.font = [UIFont systemFontOfSize:14];
        self.contentLab.textAlignment = NSTextAlignmentRight;
        self.contentLab.numberOfLines = 0;
        [self.bgView addSubview:self.contentLab];
        
        self.title4Lab = [UILabel new];
        self.title4Lab.textColor = HexColor(0x9C9DB3);
        self.title4Lab.font = [UIFont systemFontOfSize:14];
        self.title4Lab.text = @"回单日期：";
        [self.bgView addSubview:self.title4Lab];
        
        self.name2Lab = [UILabel new];
        self.name2Lab.textColor = HexColor(0x2B2C44);
        self.name2Lab.font = [UIFont systemFontOfSize:14];
        self.name2Lab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.name2Lab];
        
        self.title5Lab = [UILabel new];
        self.title5Lab.textColor = HexColor(0x9C9DB3);
        self.title5Lab.font = [UIFont systemFontOfSize:14];
        self.title5Lab.text = @"回单附件：";
        [self.bgView addSubview:self.title5Lab];
        
        self.look2Btn = [UIButton new];
        [self.look2Btn setTitleColor:Color_ThemeColor forState:0];
        self.look2Btn.titleLabel.font = BoldFontOfSize(14);
        self.look2Btn.titleLabel.textAlignment = NSTextAlignmentRight;
        [self.look2Btn addTarget:self action:@selector(look2Click) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.look2Btn];
        
        self.statusImgView = [UIImageView new];
        self.statusImgView.image = [UIImage imageNamed:@"woshou_img_void"];
        [self.bgView addSubview:self.statusImgView];
    }
    return self;
}

- (void)look1Click {
    if (self.model.signImg.count) {
        XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:self.model.signImg currentImageIndex:0];
        browser.browserStyle = XLPhotoBrowserStyleIndexLabel;//微博样式
        [browser setActionSheetWithTitle:nil delegate:self cancelButtonTitle:nil deleteButtonTitle:nil otherButtonTitles:@"保存图片", nil];
    }
}

- (void)look2Click {
    if (self.model.receipt_turnoverImg.count) {
        XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:self.model.receipt_turnoverImg currentImageIndex:0];
        browser.browserStyle = XLPhotoBrowserStyleIndexLabel;//微博样式
        [browser setActionSheetWithTitle:nil delegate:self cancelButtonTitle:nil deleteButtonTitle:nil otherButtonTitles:@"保存图片", nil];
    }
}

- (void)photoBrowser:(XLPhotoBrowser *)browser clickActionSheetIndex:(NSInteger)actionSheetindex currentImageIndex:(NSInteger)currentImageIndex {
    [browser saveCurrentShowImage];
}

- (void)setModel:(WaybillMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 30;
    
    self.statusImgView.nim_top = 20;
    self.statusImgView.nim_width = 62;
    self.statusImgView.nim_height = 40;
    self.statusImgView.nim_centerX = self.bgView.nim_width * 0.5;
    self.statusImgView.hidden = ![self.model.signStatus isEqualToString:@"2"];
    
    self.title1Lab.nim_left = 15;
    self.title1Lab.nim_top = 20;
    [self.title1Lab sizeToFit];
    
    self.name1Lab.text = self.model.signUser;
    [self.name1Lab sizeToFit];
    self.name1Lab.nim_left = self.bgView.nim_width - 20 - self.name1Lab.nim_width;
    self.name1Lab.nim_centerY = self.title1Lab.nim_centerY;
    
    self.title2Lab.nim_left = 15;
    self.title2Lab.nim_top = 15 + self.title1Lab.nim_bottom;
    [self.title2Lab sizeToFit];
    
    CGSize size = [FactoryMethod sizeWithText:@"查看图片" font:self.look1Btn.titleLabel.font maxSize:CGSizeMake(0, 0)];
    self.look1Btn.nim_width = size.width;
    self.look1Btn.nim_height = size.height;
    self.look1Btn.nim_left = self.bgView.nim_width - 20 - self.look1Btn.nim_width;
    self.look1Btn.nim_centerY = self.title2Lab.nim_centerY;
    [self.look1Btn setTitle:self.model.signImg.count ? @"查看图片" : @"--" forState:0];
    
    self.title3Lab.nim_left = 15;
    self.title3Lab.nim_top = 15 + self.title2Lab.nim_bottom;
    [self.title3Lab sizeToFit];
    
    self.contentLab.text = self.model.signRemarks;
    self.contentLab.nim_width = self.bgView.nim_width - 20 - self.title3Lab.nim_right - 40;
    [self.contentLab sizeToFit];
    self.contentLab.nim_left = self.title3Lab.nim_right + 40;
    self.contentLab.nim_top = self.title3Lab.nim_top;
    self.contentLab.nim_width = self.bgView.nim_width - 20 - self.title3Lab.nim_right - 40;
    
    self.title4Lab.nim_left = 15;
    self.title4Lab.nim_top = self.model.signRemarks.length ? 15 + self.contentLab.nim_bottom : 15 + self.title3Lab.nim_bottom;
    [self.title4Lab sizeToFit];
    
    self.name2Lab.text = self.model.receipt_turnoverTime;
    [self.name2Lab sizeToFit];
    self.name2Lab.nim_left = self.bgView.nim_width - 20 - self.name2Lab.nim_width;
    self.name2Lab.nim_centerY = self.title4Lab.nim_centerY;
    
    self.title5Lab.nim_left = 15;
    self.title5Lab.nim_top = 15 + self.title4Lab.nim_bottom;
    [self.title5Lab sizeToFit];
    
    self.look2Btn.nim_width = size.width;
    self.look2Btn.nim_height = size.height;
    self.look2Btn.nim_left = self.bgView.nim_width - 20 - self.look2Btn.nim_width;
    self.look2Btn.nim_centerY = self.title5Lab.nim_centerY;
    [self.look2Btn setTitle:self.model.receipt_turnoverImg.count ? @"查看图片" : @"--" forState:0];
    
    self.bgView.nim_height = self.title5Lab.nim_bottom + 20;
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
